package awd.bj.jls.webs.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import awd.bj.jls.model.JqModel;
import awd.bj.jls.webs.api.JlsServersApi;
import awd.bj.jls.webs.api.model.User;
import awd.bj.jls.webs.utils.PagerResult;
import awd.bj.jls.webs.utils.QueryParam;
import awd.bj.jls.webs.utils.ResponseMessage;
import awd.bj.jls.webs.utils.Result;

/**
 * @Description
 * @Author WS
 * @Date 2019-06-24 14:00
 */
@RequestMapping("/jls_jq")
@RestController
public class JqController extends BaseAction{

    @Autowired
    private JlsServersApi jlsServersApi;
    
    @RequestMapping(value = "/getJqTree",method = {RequestMethod.GET,RequestMethod.POST})
    public Result<?> getJqTree(@RequestParam(value = "id",required = false,defaultValue = "") String id){
    	User users = getCurrentUser();
    	jlsServersApi.getJqTree(id,users.getJsbh());
    	return null;
    }
    
    @GetMapping("/getJqCombotree")
    @ResponseBody
    public List<Map<String,Object>> getJqCombotree(){
    	User users = getCurrentUser();
    	QueryParam param =new QueryParam();
    	param.and("jsbh", users.getJsbh());
    	param.and("state", "R2");
    	ResponseMessage<PagerResult<JqModel>> re= jlsServersApi.jqQueryForPage(param);
    	List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
    	if(re.getResult().getTotal() != 0 ) {
    		re.getResult().getData().forEach(x->{
    			Map<String,Object> map = new HashMap<>();
    			map.put("id", x.getJqh());
    			map.put("text", x.getJqmc());
    			map.put("state","closed");
    			map.put("isparent","true");
    			list.add(map);
    		});
    	}
		return list;
    }
}
